package com.shuqi.activity.viewport;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.shuqi.common.utils.Log4an;
import com.shuqi.controller.R;

/**
 * 提示Dialog
 * 
 * @author chenwei
 * 
 */
public class ConfirmDialog {

    private static final String TAG = "ConfirmDialog";

    private BottomDialog dialog;

    private View view;

    private TextView tvTitle;

    private TextView tvContent;

    private Button btnLeft;

    private Button btnRight;

    private Context context;

    public ConfirmDialog(Context context) {
        this.context = context;

        view = View.inflate(context, R.layout.view_dialog_confirm, null);

        tvTitle = (TextView) view.findViewById(R.id.tv_view_dialog_title);
        tvContent = (TextView) view.findViewById(R.id.tv_view_dialog_content);
        btnLeft = (Button) view.findViewById(R.id.btn_view_dialog_left);
        btnRight = (Button) view.findViewById(R.id.btn_view_dialog_right);

        btnLeft.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        btnRight.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        dialog = new BottomDialog(context, view);

    }

    public void show(String title, String content) {

        tvTitle.setText(title);

        tvContent.setText(content);

        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public void setOnClickListenerLeft(OnClickListener oListener) {
        btnLeft.setOnClickListener(oListener);
        Log4an.d(TAG, "left");
    }

    public void setOnClickListenerRight(OnClickListener oListener) {
        btnRight.setOnClickListener(oListener);
        Log4an.d(TAG, "right");
    }

}
